"use strict";

module.exports = (app) => {
  const { ENUM, INTEGER, DATE, Op } = app.Sequelize;

  const Favorites = app.model.define(
    "word_favorites",
    {
      id: {
        type: INTEGER,
        primaryKey: true,
        autoIncrement: true,
      },
      user_id: {
        type: INTEGER,
        allowNull: false,
        references: {
          model: 'users',
          key: 'id',
        },
      },
      word_id: {
        type: INTEGER,
        allowNull: false,
        references: {
          model: 'words',
          key: 'id',
        },
      },
      created_at: DATE,
      updated_at: DATE,
    },
    {
      freezeTableName: true,
    }
  );
  // 关联用户和单词
  Favorites.associate = () => {
    Favorites.belongsTo(app.model.Word, { foreignKey: "word_id" });
    Favorites.belongsTo(app.model.User, { foreignKey: "user_id" });
  };
  return Favorites;
};
